/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amse.grigory.dchess.view;

import java.util.*;
import org.amse.grigory.dchess.kernel.*;
import org.amse.grigory.dchess.rules.*;

/**
 *
 * @author grigory
 */
@Deprecated
public class ConsoleView implements IView {

    boolean myExit = false;
    Model myModel;

    public ConsoleView(Model model) {
        myModel=model; 
    }

    public void show() {
        System.out.println(myModel);
    }

    public void getMove() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int x, y, tx, ty;
            if (myModel.getColor() == 1) {
                System.out.println("White's turn!");
            } else {
                System.out.println("Black's turn!");
            }
            System.out.println("Enter x,y,tx,ty(q to exit):");
            try {
                String number = sc.next();
                if (number.equals("q")) {
                    myExit = true;
                    break;
                }
                x = Integer.parseInt(number);
                number = sc.next();
                y = Integer.parseInt(number);
                number = sc.next();
                tx = Integer.parseInt(number);
                number = sc.next();
                ty = Integer.parseInt(number);
                if (myModel.makeMove(x, y, tx, ty)) {
                    int t=myModel.isWin();
                    if (t==Rules.BLACK_WIN){
                        System.out.println("Black has won!");
                    }
                    if (t==Rules.WHITE_WIN){
                        System.out.println("White has won!");
                    }
                    if (t==Rules.DRAW){
                        System.out.println("Draw!");
                    }
                    break;
                } else {
                    System.out.println("***Illegal move!***");
                    show();
                }
            } catch (NumberFormatException e) {
                System.out.println("***Wrong Format!!!***");
                show();
            }

        }
    }

    public boolean getExit() {
        return myExit;
    }
}
